package com.you.springcloud.alibaba.demo.controller;

import com.you.springcloud.alibaba.demo.api.ServiceA;
import com.you.springcloud.alibaba.demo.vo.UserVo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {

    @Reference(version = "1.0.0",
            interfaceClass = ServiceA.class,
            cluster = "failfast",
            timeout = 6000,
            retries = 0
    )
    private ServiceA serviceA;

    @GetMapping("/greet")
    public String greet(String name) {
        return serviceA.greet(name);
    }

    /**
     * 新增用户
     *
     * @param id
     * @param name
     * @param age
     * @return
     */
    @GetMapping("/addUser")
    public String addUser(int id, String name, int age) {
        UserVo userVo = new UserVo();
        userVo.setId(id);
        userVo.setName(name);
        userVo.setAge(age);
        return serviceA.addUser(userVo);
    }

    @GetMapping("/findUserById")
    public List<UserVo> findUserById(String id) {
        return serviceA.findUserById(id);
    }

}
